package com.ucenter.server.org.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ucenter.server.org.dao.PositionInfoDao;
import com.ucenter.server.org.pojo.PositionInfo;
import com.ucenter.server.org.service.PositionInfoService;
import com.system.comm.model.Page;
import com.system.comm.utils.FrameNoUtil;
import com.system.comm.utils.FrameStringUtil;
import com.system.handle.model.ResponseFrame;
import com.system.handle.model.ResponseCode;

/**
 * position_info的Service
 * @author autoCode
 * @date 2018-12-01 09:50:14
 * @version V1.0.0
 */
@Component
public class PositionInfoServiceImpl implements PositionInfoService {

	@Autowired
	private PositionInfoDao positionInfoDao;
	
	@Override
	public ResponseFrame saveOrUpdate(PositionInfo positionInfo) {
		ResponseFrame frame = new ResponseFrame();
		if(FrameStringUtil.isEmpty(positionInfo.getPositionId())) {
			positionInfo.setPositionId(FrameNoUtil.uuid());
			positionInfoDao.save(positionInfo);
		} else {
			positionInfoDao.update(positionInfo);
		}
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}

	@Override
	public PositionInfo get(String positionId) {
		return positionInfoDao.get(positionId);
	}

	@Override
	public ResponseFrame pageQuery(PositionInfo positionInfo) {
		positionInfo.setDefPageSize();
		ResponseFrame frame = new ResponseFrame();
		int total = positionInfoDao.findPositionInfoCount(positionInfo);
		List<PositionInfo> data = null;
		if(total > 0) {
			data = positionInfoDao.findPositionInfo(positionInfo);
		}
		Page<PositionInfo> page = new Page<PositionInfo>(positionInfo.getPage(), positionInfo.getSize(), total, data);
		frame.setBody(page);
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}
	
	@Override
	public ResponseFrame delete(String positionId) {
		ResponseFrame frame = new ResponseFrame();
		positionInfoDao.delete(positionId);
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}

	@Override
	public List<PositionInfo> findByDepId(String depId) {
		return positionInfoDao.findByDepId(depId);
	}
}